# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file '获取选中的日期.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2 import QtWidgets, QtCore, QtGui
import  sys


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.calendarWidget = QtWidgets.QCalendarWidget(self.centralwidget)
        # self.calendarWidget.setObjectName(u"calendarWidget")
        self.calendarWidget.setGeometry(QRect(180, 80, 421, 331))

        self.calendarWidget.selectedDate()    # 设置日历默认选中的是当前日期
        self.calendarWidget.setMinimumDate(QtCore.QDate(1752, 9, 14))    # 设置最小的日期
        self.calendarWidget.setMaximumDate(QtCore.QDate(9999, 12, 31))   # 设置最大的日期
        self.calendarWidget.setFirstDayOfWeek(QtCore.Qt.Monday)          # 设置每周的第一天是星期一
        self.calendarWidget.setGridVisible(True)                         # 设置网格线可见
        # 设置可以选中单个日期
        self.calendarWidget.setSelectionMode(QtWidgets.QCalendarWidget.SingleSelection)
        # 设置水平表头为简短形式，及"周一"
        self.calendarWidget.setHorizontalHeaderFormat(QtWidgets.QCalendarWidget.ShortDayNames)
        # 设置垂直表头为周数
        self.calendarWidget.setVerticalHeaderFormat(QtWidgets.QCalendarWidget.ISOWeekNumbers)
        self.calendarWidget.setNavigationBarVisible(True)    # 设置显示导航栏
        self.calendarWidget.setDateEditEnabled(True)         # 设置日期可以编辑
        self.calendarWidget.setObjectName("calenderWidget")

        # 选中的日期变化时显示选择的日期
        self.calendarWidget.selectionChanged.connect(self.getdate)

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 800, 26))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u83b7\u53d6\u9009\u4e2d\u65e5\u671f", None))
    # retranslateUi

    # 定义一个获取日期的槽函数
    def getdate(self):
        from PySide2.QtWidgets import QMessageBox
        date = QtCore.QDate(self.calendarWidget.selectedDate())    # 获取当前选中日期的QDate对象
        year = date.year()
        month = date.month()
        day = date.day()
        QMessageBox.information(MainWindow, "提示", str(year)+'-'+str(month)+'-'+str(day), QMessageBox.Ok)



if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())